package router

import (
	"go-http/netdisk/api"
	"go-http/netdisk/middleware/jwt"

	"github.com/gin-gonic/gin"
)

func Init() *gin.Engine {
	r := gin.New()

	r.Use(gin.Logger(), gin.Recovery())

	apiGroup := r.Group("/api")
	{
		userGroup := apiGroup.Group("/user")
		{
			userGroup.GET("/refresh", api.UserRefresh)
			userGroup.POST("/register", api.UserRegister)
			userGroup.POST("/login", api.UserLogin)
			userAuth := userGroup.Use(jwt.Authorize)
			{
				userAuth.GET("/info", api.UserInfo)
			}
		}

		fileGroup := apiGroup.Group("/file")
		{
			fileAuth := fileGroup.Use(jwt.Authorize)
			{
				fileAuth.GET("page", api.GetPage)
				fileAuth.POST("upload", api.Upload)
				fileAuth.POST("create_dir", api.CreateDirectory)
			}
		}
	}

	r.Static("/static", "html2")

	return r
}
